package bishi.kaizi;

import java.util.ArrayList;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2022/03/12 20:50
 */
public class _06 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     * <p>
     * 根据 输入列表对应的物体受力情况，按物理规律计算出 输入处理完毕后物体所在的坐标位置。
     *
     * @param inputList int整型ArrayList 输入的物体受力列表情况
     * @return float浮点型
     */
    public float GetLastPos(ArrayList<Integer> inputList) {
        float res = (float) 0.0;
        float v = (float) 0.0;
        for (Integer a : inputList) {
            float nowLen;
            float nextV = (float) 0.0;
            if (v != 0) {
                if (a * v < 0) {//反方向
                    double pp = Math.abs(a) - Math.abs(v);
                    if (pp > 0) {
                        //会造成 0的情况,需要加以判断
                        float aa = (a > 0 ? a - 1 : a + 1);
                        if (Math.abs(a) + 1 > Math.abs(v)) {
                            double time = Math.abs(v + a) / 10;
                            double aaa = (Math.abs(a) > 1 ? a > 0 ? a - 1 : a + 1 : 0);
                            nowLen = (float) (0.5 * aa * time * time);
                            nowLen += (float) (0.5 * aaa * time * time);
                            res += nowLen;
                            nextV = (float) (aaa * (1 - time));
                        } else {
                            nowLen = (float) (v + 0.5 * (a > 0 ? a - 1 : a + 1));
                            res += nowLen;
                            nextV = v + a;
                        }
                    }
                } else {
                    if (Math.abs(a) > 1) {
                        nowLen = (float) (v + 0.5 * (a > 0 ? a - 1 : a + 1));
                        res += nowLen;
                        nextV = v + a;
                    }
                }
                v = nextV;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        _06 one = new _06();
        System.out.println(one.GetLastPos(new ArrayList<Integer>() {{
            add(1);
            add(3);
            add(-1);
        }}));
    }
}
